//early_activity
exports.early_activity = function (req, res) {

    //获取restful参数
    var restfulParams = req.routeInfo.restfulParams;

    //最终结果
    var resultData = {};

    var earlyforumActivityList = [];

    var endActivityList = 0;

    var skip = restfulParams.skip == undefined ? 0 : restfulParams.skip;

    var limit = restfulParams.limit == undefined ? config.publicConfig.LIMIT : restfulParams.limit;
    var nowTime = common.nowTime(false);
    //任务流创建
    async.waterfall([

        function (cb) {

            R.SEND_HTTP(
                req,
                {
                    url: CORE_APIConfig.coreAPI.searchForumActivity+ "/skip/" + skip + "/limit/" + limit,
                    method: 'POST',
                    data: {
                        fields: [
                            "fa_id",
                            "fa_title",
                            "fa_image",
                            "fa_a_type",
                            "fa_start_time",
                            "fa_end_time",
                            "fa_old_price",
                            "fa_price"
                        ].join(",")
                    }
                },
                function (err, data) {

                    endActivityList = data.data;
                    cb();
                }
            );
        },
        function (cb) {

            //创建添加任务
            var tasks = [];

            //循环节点列表
            endActivityList.forEach(function (item, i) {

                //创建每一个插入任务
                tasks.push(function (cb) {

                    //查询对该用户的回复
                    R.SEND_HTTP(
                        req,
                        {
                            url: CORE_APIConfig.coreAPI.searchFrumActivityAppointment + "/is_delete/0/faa_faid/" + item.fa_id + "/faa_uid/" + restfulParams.u_id,
                            method: 'POST',
                            data: {
                                fields: ["faa_id"].join(",")
                            }
                        },
                        function (err, data) {

                            var is_exist = data.data;
                            if (is_exist.length <= 0) {
                                item.isAppointment = 0;
                            } else {
                                item.isAppointment = 1;
                            }
                            cb();
                        });
                });
            });
            async.waterfall(tasks, cb);

        },
        function (cb) {

            for (var i = 0; i < endActivityList.length; i++) {
                if (endActivityList[i].fa_end_time < nowTime) {
                    earlyforumActivityList[i] = endActivityList[i];
                    resultData.earlyActivity = earlyforumActivityList
                }
                cb();

            }
        }
    ], function (err, result) {

        //返回最终拼接结果
        RES.response(res, true, resultData);

    });

}